package com.glsc.ngateway.opmanage.service.deposit;

import com.glsc.ngateway.common.api.common.utils.PageUtil;
import com.glsc.ngateway.common.base.domain.mysql.opmanagemain.deposit.DepositoryPaymentPlanXinYiLog;
import com.glsc.ngateway.common.base.repo.mysql.opmanagemain.deposit.DepositoryPaymentPlanXinYiLogRepository;
import com.glsc.ngateway.opmanage.utils.DateUtils;
import com.glsc.ngateway.opmanage.utils.SpecificationUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;

@Service
@Slf4j
public class DepositoryPaymentPlanXinYiLogService {

    @Resource
    private DepositoryPaymentPlanXinYiLogRepository depositoryPaymentPlanXinYiLogRepository;


    /**
     * 分页查询
     *
     * @param pageNo
     * @param pageSize
     * @param param
     * @return
     */
    public Page<DepositoryPaymentPlanXinYiLog> page(int pageNo, int pageSize, Map<String, Object> param) {
        Sort.Direction direction = Sort.Direction.DESC;
        String sort = "createTime";

        if (Objects.isNull(param.get("EQ_effectDate"))) {
            param.put("EQ_effectDate", DateUtils.getNowDateString());
        }

        pageNo = PageUtil.initPageNo(pageNo);
        pageSize = PageUtil.initPageSize(pageSize);

        Pageable pageable = PageRequest.of(pageNo - 1, pageSize, direction, sort);
        Page<DepositoryPaymentPlanXinYiLog> page = depositoryPaymentPlanXinYiLogRepository.findAll(SpecificationUtil.buildSpecification(param, DepositoryPaymentPlanXinYiLog.class), pageable);

        return page;
    }

    /**
     * 保存
     *
     * @param obj
     * @return
     */
    public DepositoryPaymentPlanXinYiLog save(DepositoryPaymentPlanXinYiLog obj) {
        return depositoryPaymentPlanXinYiLogRepository.save(obj);
    }


}
